package com.qiaofang.generator.facade.impl;

import cn.hutool.json.JSONUtil;
import com.qiaofang.common.request.DataRequest;
import com.qiaofang.common.response.DataResultResponse;

import com.qiaofang.generator.service.service.ReceivableDataService;
import com.qiaofang.generator.stub.bean.ReceivableDataDTO;
import com.qiaofang.generator.stub.facade.V20Facade;
import com.qiaofang.sysconfig.stub.bean.SystemConfigDTO;
import com.qiaofang.sysconfig.stub.feign.client.SystemConfigClient;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @ClassName SysConfigFacadeImpl
 * @Description
 * @Author zhouyao
 * @Date 2021/1/6 17:59
 **/
@RestController
@Slf4j
public class V20FacadeImpl implements V20Facade {

    @Autowired
    private SystemConfigClient systemConfigClient;

    @Autowired
    private ReceivableDataService receivableDataService;

    @Override
    public DataResultResponse<Object> listSystemConfigByConfigNames(@RequestBody DataRequest<List<String>> request) {
        log.info("request = {}" , JSONUtil.toJsonStr(request));
        List<String> param = request.getParam();
        Map<String, List<SystemConfigDTO>> result = systemConfigClient.listSystemConfigByConfigNames(param);
        return DataResultResponse.ok(result);
    }

    @Override
    public DataResultResponse<ReceivableDataDTO> receivableDataWriteV20(@RequestBody@ApiParam("应收数据uuid") DataRequest<String> request) {

        ReceivableDataDTO receivableDataByUuid =  receivableDataService.getReceivableDataByUuid(request.getParam());
        return DataResultResponse.ok(receivableDataByUuid);
    }
}

